﻿using mak_bll;
using Mak_model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using System.Windows.Forms;

namespace markets
{
    public partial class buygoods : Form
    {
        public buygoods()
        {
            InitializeComponent();
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F2)
            {
                textBox1.Focus();
            }
            if (e.KeyCode == Keys.F5)
            {
                button2.Focus();
            }
        }

        List<data> thisshow = new List<data>();

        luoji buygoods = new luoji();
        private void button1_Click(object sender, EventArgs e)
        {
            //当结果 为空
            if (textBox1.Text != "")
            {
                List<GoodsInfo> lie = buygoods.QueryListByCode(textBox1.Text);
                data item = new data();
                if (lie.Count == 0)
                {
                    MessageBox.Show("商品编码输入错误");
                }
                else if (lie.Count == 1)
                {
                    MessageBox.Show(thisshow[0].GoodsName.ToString());
                    item.GoodsName = thisshow[0].GoodsName;
                    item.SalePrice = thisshow[0].SalePrice;
                    item.goodsCount = 1;
                    lie.Add(item);
                }
                else 
                {
                    ShowData xuanze = new ShowData(null);
                    xuanze.show = lie;
                    xuanze.ShowDialog();
                    GoodsInfo sp = xuanze.xuanzeo;
                    item.GoodsName = thisshow[0].GoodsName;
                    item.SalePrice = thisshow[0].SalePrice;
                    item.goodsCount = 1;
                    lie.Add(item);

                }
                bangding();
                textBox1.Text = "";

                
                
            }
            
        }


        public void bangding()
        {
            dataGridView1.DataSource = new BindingList<data>(thisshow);
        
        
        }


        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (textBox1.Text != "")
                {
                    button1_Click(null, null);
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Test");
        }

        private void buygoods_ui_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;
        }
    }
}
